/**
 * 部门js
 */
var userInfoDetail = {
	curPage : 0,
	pageSize : 10,
	dataCache : null,

	startEvent : function() {
		// 按回车键登录事件
		document.onkeydown = function(e) {
			var ev = document.all ? window.event : e;
			if (ev.keyCode == 13) {
				userInfoDetail.curPage = 1;
				userInfoDetail.setPageChange(null);
				userInfoDetail.search();
			}
		};
		
		jsUtils.controlFunctionBtn();
	},

	getChannelResource : function() {
		var url = 'mgr/userChannelCtrl/list';
		var params = {
			'curPage' : 0,
			'pageSize' : 9999
		};
		var cb = function(data) {
			if (data.resultCode == 200) {
				var option = '<option value="">请选择</option>';
				for (var i = 0; i < data.result.length; i++) {
					var singleObj = data.result[i];
					option = option + '<option value="' + singleObj.channelId + '">'
						+ singleObj.name + '</option>';
				}
				$('select[name="channel"]').append(option);
			}
		};
		sendApiNoLoad(url, params, cb, 'POST');

	},
	bindEvent : function() {
		// 查询
		$('#searchData').click(function() {
			userInfoDetail.curPage = 1;
			userInfoDetail.setPageChange(null);
			userInfoDetail.search();
		});

		 
		
		$('#excel').on('click', function() { 
			var url = '../../../mgr/userPointsDetailCtrl/excel';
			if (typeof (pageIdx) != "undefined") {
				userInfoDetail.curPage = pageIdx;
			}

			 
			var userPhoneNum = $.trim($('#searchModForm input[name="userPhoneNum"]').val());
			var finRealName = $.trim($('#searchModForm input[name="finRealName"]').val());
			var channel = $.trim($('#searchModForm select[name="channel"]').val());
			 
			
			location.href = url+"?userPhoneNum=" + userPhoneNum + "&finRealName=" + finRealName   
				+ "&channel=" + channel;
		});
	},

	// 设置分页
	setPageChange : function(delCurPage) {
		var url = 'mgr/userPointsDetailCtrl/list';
	
		if (typeof (pageIdx) != "undefined") {
			userInfoDetail.curPage = pageIdx;
		}

	 
		var userPhoneNum = $.trim($('#searchModForm input[name="userPhoneNum"]').val());
		var finRealName = $.trim($('#searchModForm input[name="finRealName"]').val());
		var channel = $.trim($('#searchModForm select[name="channel"]').val());
		 
		
		var params = {
			'userPhoneNum' : userPhoneNum,
			'finRealName' : finRealName,
			'channel' : channel,
			'curPage' : 0,
			'pageSize' : 9999999
		};

		var cb = function(data) {
			if (data.resultCode == 200) {
				var totalCount = data.size;
				var pageTotal = (totalCount / userInfoDetail.pageSize > 0) ? Math
						.ceil(totalCount / userInfoDetail.pageSize) : 1;
				pageHelper.init(pageTotal, totalCount, userInfoDetail.search,
						delCurPage); // 翻页事件
			}
		};
		sendApiNoLoad(url, params, cb, 'POST');
	},

	// 查询交易记录
	search : function(pageIdx) {
		var url = 'mgr/userPointsDetailCtrl/list';
		if (typeof (pageIdx) != "undefined") {
			userInfoDetail.curPage = pageIdx;
		}

	 
		var userPhoneNum = $.trim($('#searchModForm input[name="userPhoneNum"]').val());
		var finRealName = $.trim($('#searchModForm input[name="finRealName"]').val());
		var channel = $.trim($('#searchModForm select[name="channel"]').val());
		 
	 
		var params = {
				'userPhoneNum' : userPhoneNum,
				'finRealName' : finRealName,
				'channel' : channel,
				'curPage' : userInfoDetail.curPage,
				'pageSize' : userInfoDetail.pageSize
		};
		
		var cb = function(data) {
			$('#tableList tbody').empty();
			var tr = '';
			if (data.result != null && data.result.length > 0) {
				for (var i = 0; i < data.result.length; i++) {
					var singleObj = data.result[i];
					
					tr += '<tr><td><input type="hidden" name="id" value="'
							+ singleObj.userId
							+ '"/>'
							+ (i + 1)
							+ '</td><td>'
							+ singleObj.col010userId
							+ '</td><td>'
							+ singleObj.col020userPhoneNum
							+ '</td><td>'
							+ singleObj.col030isTieCard
							+ '</td><td>'
							+ singleObj.col040finName
							+ '</td><td>'
							+ singleObj.col050finPhoneNum
							+ '</td><td>'
							+ singleObj.col060finDutName
							+ '</td><td>'
							+ singleObj.col070finDepName
						 	+ '</td></tr>';
				}
			} else {
				tr = '<tr><td colspan="6" style="text-align: center;color: red;">暂无数据</td></tr>';
			}
			$('#tableList tbody').html(tr);
			userInfoDetail.bindEventOtherBtn();
			jsUtils.controlFunctionBtn();
		};

		sendApiNoLoad(url, params, cb, 'POST');
	},

	bindEventOtherBtn : function() {
		
	},

	init : function() {
		jsUtils.controlFunctionBtn();
		userInfoDetail.getChannelResource();
		userInfoDetail.setPageChange(null);
		userInfoDetail.search();
		userInfoDetail.startEvent();
		userInfoDetail.bindEvent();
		
	}
};

$(document).ready(function() {
	userInfoDetail.init();
});

//提供给外部刷新调用
function refashData() {
	userInfoDetail.setPageChange(null);
	userInfoDetail.search();
}
